﻿<%@ Control Language="C#" ClassName="SiteMapControl" %>

<script runat="server">

  public string Prod_Cat_ID { get; set; }
  public string NewCatID { get; set; }
  public string B2C_CODE { get; set; }
  public string B2C_CODE_NAME { get; set; }

  protected void Page_Load(object sender, EventArgs e)
  {
    if (Cache["SiteMapList"] == null) CommonUtil.GenericSiteMapList();
    
    if (!string.IsNullOrEmpty(Request.QueryString["category"]))
    {
      Prod_Cat_ID = Request.QueryString["category"];            
    }
    if (!string.IsNullOrEmpty(Request.QueryString["NewCatID"]))
    {
      NewCatID = Request.QueryString["NewCatID"];   
    }    
    
    B2CSiteMap.Controls.Clear();
    HyperLink link = new HyperLink();
    link.CssClass = "current";

    if (!string.IsNullOrEmpty(NewCatID))
    {
      B2CSiteMap.Controls.Add(new LiteralControl("各館新品 / "));
      switch (NewCatID)
      {
        case "6":
          link.Text = "長榮獨家";
          link.NavigateUrl = "~/Products/ProductsList.aspx?category=1";
          B2CSiteMap.Controls.Add(link);
          break;
        case "7":
          link.Text = "寰宇精品";
          link.NavigateUrl = "~/Products/ProductsList.aspx?category=2";
          B2CSiteMap.Controls.Add(link);
          break;
        case "8":
          link.Text = "消費電子";
          link.NavigateUrl = "~/Products/ProductsList.aspx?category=3";
          B2CSiteMap.Controls.Add(link);
          break;
        case "9":
          link.Text = "居家生活";
          link.NavigateUrl = "~/Products/ProductsList.aspx?category=4";
          B2CSiteMap.Controls.Add(link);
          break;
        case "10":
          link.Text = "美容保健";
          link.NavigateUrl = "~/Products/ProductsList.aspx?category=5";
          B2CSiteMap.Controls.Add(link);
          break;
        case "11":
          link.Text = "美食饗宴";
          link.NavigateUrl = "~/Products/ProductsList.aspx?category=6";
          B2CSiteMap.Controls.Add(link);
          break;
        case "12":
          link.Text = "哩上加禮";
          link.NavigateUrl = "~/Products/ProductsListMileages.aspx?category=7";
          B2CSiteMap.Controls.Add(link);
          break;
        case "13":
          link.Text = "優惠情報";
          link.NavigateUrl = "~/Products/ProductsList.aspx?category=8";
          B2CSiteMap.Controls.Add(link);
          break;
        default:
          link.Text = "長榮獨家";
          link.NavigateUrl = "~/Products/ProductsList.aspx?category=1";
          B2CSiteMap.Controls.Add(link);
          break;
      }
    }
    else if (!string.IsNullOrEmpty(Prod_Cat_ID) && string.IsNullOrEmpty(B2C_CODE))
    {
      Dictionary<string, PlaceHolder> SiteMapList =
        Cache["SiteMapList"] as Dictionary<string, PlaceHolder>;
      var simemap = SiteMapList.Where(s => s.Key == Prod_Cat_ID).SingleOrDefault();
      B2CSiteMap.Controls.Add(simemap.Value);
    }
    else if (!string.IsNullOrEmpty(Prod_Cat_ID) && !string.IsNullOrEmpty(B2C_CODE))
    {
      string CurrentCatID = Prod_Cat_ID.Replace("(", "").Replace(")", "").Replace("X", "");
      string[] CatArray = CurrentCatID.Split(',');
      if (CatArray.Length > 0)
      {
        string catID = CatArray[0].ToString();
        Dictionary<string, PlaceHolder> SiteMapList = Cache["SiteMapList"] as Dictionary<string, PlaceHolder>;
        var simemap = SiteMapList.Where(s => s.Key == catID).SingleOrDefault();

        if (simemap.Value != null)
        {
          //先消去CSS        
          foreach (var item in simemap.Value.Controls)
          {
            if (item is HyperLink)
            {
              (item as HyperLink).CssClass = "";
            }
          }
          B2CSiteMap.Controls.Add(simemap.Value);

          B2CSiteMap.Controls.Add(new LiteralControl(" / "));
          HyperLink ProductLink = new HyperLink();
          ProductLink.CssClass = "current";
          ProductLink.Text = B2C_CODE_NAME;
          ProductLink.NavigateUrl = "~/Products/ProductDetail.aspx?B2C_CODE=" + B2C_CODE;
          B2CSiteMap.Controls.Add(ProductLink);
        }
      }
    }
  }

</script>
<asp:PlaceHolder ID="B2CSiteMap" runat="server" />
